﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Trig_AMJ_HR_Forms
{
    class SP_Group
    {
        public static string SiteURL = SPContext.Current.Site.Url + "/sites/forms/";

        private static void GetUserRoles()
        {
            using (SPSite site = new SPSite(SiteURL))
            {

                SPWeb web = site.OpenWeb();
                //Console.WriteLine("\n\n Roles Assignments:");

                foreach (SPRoleAssignment roleA in web.RoleAssignments)
                {
                    Console.WriteLine("The following Role definition bindings exist for" + roleA.Member.Name);
                    foreach (SPRoleDefinition roledef in roleA.RoleDefinitionBindings)
                    {
                        //Console.WriteLine(roledef.Name);
                    }
                }
               // Console.ReadLine();
            }
        }
        public SPUserCollection GetUsersGroups()
        {
          SPUserCollection userCollection =null;
            using (SPSite site = new SPSite(SiteURL))
            {

                SPWeb web = site.OpenWeb();
                SPGroupCollection groupCollection = web.SiteGroups;

                foreach (SPGroup group in groupCollection)
                {
                    
                    //Console.WriteLine("Group Name :" + group.Name + "\n");
                    if (group.Name == "AmjAdmin")
                    {
                        userCollection = group.Users;
                        //foreach (SPUser user in userCollection)
                        //{
                        //    Console.WriteLine("User Name: " + user.Name + " Email: " + user.Email + " Login: " + user.LoginName);
                        //}
                    }
                }
                //Iterate the owners group
                SPGroup ownerGroup = web.AssociatedOwnerGroup;
                foreach (SPUser ownerUser in ownerGroup.Users)
                {
                    Console.WriteLine("User Name: " + ownerUser.Name + " Email: " + ownerUser.Email + " Login: " + ownerUser.LoginName);
                }
            }
            //Console.ReadLine();
            return userCollection;
        }

    }
}